package com.dmagic.cms.dao;

import java.util.List;

import org.springframework.stereotype.Component;

import com.dmagic.cms.common.dao.CommonDao;
import com.dmagic.cms.entity.ProductCategory;

@Component
public class ProductCategoryDao extends CommonDao<ProductCategory, Long> {
	public void batchSaveCategorys(List<ProductCategory> categorys) {
		for (ProductCategory category : categorys) {
			saveEntity(category);
		}
	}

	public List<ProductCategory> getAllParentCategory() {
		return find("from ProductCategory where parentCategoryId is null");
	}

	public List<ProductCategory> getAllProductCategoryByLanguage(Long languageId) {
		String sql = super.getDaoUtil().getQueryString("getProductCategory_sql");
		return queryBySQL(sql, entityClass, languageId);
	}

	public List<ProductCategory> getSuccessfulCaseCategoryByLanguage(Long languageId) {
		return find(
				"from ProductCategory where categoryType=3 and languageId = ? and parentCategoryId is null",
				languageId);
	}
}
